package com.pancm.test.encrypt;

import java.security.*;

public class KeyPairGeneratorExample {  

    public static void main(String[] args) throws Exception {  
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");  
        keyPairGenerator.initialize(2048); // 密钥长度，通常 2048 或 4096 位  
        KeyPair keyPair = keyPairGenerator.generateKeyPair();  
        PrivateKey privateKey = keyPair.getPrivate();  
        PublicKey publicKey = keyPair.getPublic();  

        // 打印密钥 (在生产环境中，应该安全地存储密钥)  
        System.out.println("Private Key: " + privateKey);  
        System.out.println("Public Key: " + publicKey);  
    }  
}  